//
//  ZMTopicDetailOperationView.m
//  基本框架
//
//  Created by runone02 on 2018/7/6.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "ZMTopicDetailOperationView.h"


@implementation ZMTopicDetailOperationView

- (UIView *)mainView{
    if (!_mainView) {
        _mainView = [[UIView alloc]init];
        _mainView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_mainView];
        
        [_mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_equalTo(self);
        }];
    }
    return _mainView;
}

- (UIImageView *)subjectIcon{
    if (!_subjectIcon) {
        _subjectIcon = [[UIImageView alloc]init];
        _subjectIcon.backgroundColor = [UIColor redColor];
        [self.mainView addSubview:_subjectIcon];
        [_subjectIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(12);
            make.size.mas_equalTo(self.subjectIcon.image.size);
            make.centerY.mas_equalTo(self.mainView);
        }];
    }
    return _subjectIcon;
}

- (UILabel *)subjectLabel{
    if (!_subjectLabel) {
        _subjectLabel = [[UILabel alloc]init];
        _subjectLabel.font = TITLE_FONT(30);
        _subjectLabel.textColor = [ZMColor appSupportColor];
        [self.mainView addSubview:_subjectLabel];
        [_subjectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.subjectIcon.mas_right).with.offset(5);
            make.centerY.mas_equalTo(self.mainView);
        }];
    }
    return _subjectLabel;
}

- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [ZMColor appSupportColor];
        [self.mainView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.subjectLabel.mas_right).with.offset(10);
            make.width.mas_equalTo(1);
            make.height.mas_equalTo(10);
            make.centerY.mas_equalTo(self.mainView);
        }];
    }
    return _lineView;
}


- (UIImageView *)visitIcon{
    if (!_visitIcon) {
        _visitIcon = [[UIImageView alloc]init];
        _visitIcon.backgroundColor = [UIColor yellowColor];
        [self.mainView addSubview:_visitIcon];
        [_visitIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.lineView.mas_right).with.offset(10);
            make.centerY.mas_equalTo(self.mainView);
        }];
    }
    return _visitIcon;
}

- (UILabel *)visitTotalLabel{
    if (!_visitTotalLabel) {
        _visitTotalLabel = [[UILabel alloc]init];
        _visitTotalLabel.font = TITLE_FONT(30);
        _visitTotalLabel.textColor = [ZMColor appSupportColor];
        
        [self.mainView addSubview:_visitTotalLabel];
        [_visitTotalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.visitIcon.mas_right).with.offset(5);
            make.centerY.mas_equalTo(self.mainView);
        }];
    }
    return _visitTotalLabel;
}


- (UIButton *)styleButton{
    if (!_styleButton) {
        _styleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _styleButton.titleLabel.font = TITLE_FONT(30);
        [_styleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_styleButton setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
        
        [_styleButton setImage:IMAGE(@"switch_to_double") forState:UIControlStateNormal];
        [_styleButton setImage:IMAGE(@"switch_to_signal") forState:UIControlStateSelected];
        [_styleButton addTarget:self action:@selector(clickChange:) forControlEvents:UIControlEventTouchUpInside];
        [self.mainView addSubview:_styleButton];
        [_styleButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-0);
            make.width.mas_equalTo(60);
            make.height.mas_equalTo(30);
            make.centerY.mas_equalTo(self.mainView);
        }];
    }
    return _styleButton;
}


- (void)setModel:(ZMTopicDetailModel  *)model {
    if ([model isKindOfClass:[ZMTopicDetailModel class]]) {
        _model = model;
        self.subjectLabel.text = [NSString stringWithFormat:@"%ld",model.post_count];
        
        self.visitTotalLabel.text = [NSString stringWithFormat:@"%ld",model.visitCount];
        self.styleButton.hidden = NO;
    }
}





#pragma mark - 切换布局
- (void)clickChange:(UIButton *)btn{
    btn.selected = !btn.selected;
    if (self.changeStyleBlock) {
        self.changeStyleBlock(btn.selected);
    }
}
@end
